<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <title>添加或编辑界面</title>
    <link rel="stylesheet" type="text/css" href="${basePath}/lib/layui/css/layui.css"/>
    <link rel="stylesheet" type="text/css" href="${basePath}/css/base/index.css"/>
    <link rel="stylesheet" type="text/css" href="${basePath}/css/base/theme/theme.css"/>
    <style>
        .w440{
            width: 440px !important;
        }
    </style>
</head>
<body>
<#assign isRelate = false>
<#if (fieldIsRelate?? && fieldIsRelate != '')>
<#assign isRelate = true>
</#if>
<#assign showPage = false>
<#if (allSelect?? && allSelect != '')>
<#assign showPage = true>
</#if>
<#assign showLaydate = false>
<#if (formFieldVoList??) && (formFieldVoList?size>0)>
<#list formFieldVoList as formFieldVo>
<#if formFieldVo.type == 'dateTime'>
<#assign showLaydate = true>
<#break>
</#if>
</#list>
</#if>
<#assign showFileUtil = false>
<#if (formFieldVoList??) && (formFieldVoList?size>0)>
<#list formFieldVoList as formFieldVo>
<#if formFieldVo.type == 'file'>
<#assign showFileUtil = true>
<#break>
</#if>
</#list>
</#if>
<div class="page-content-wrap clearfix">
    <form class="layui-form" id="tool">
        <div class="layui-tab">
            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show">
                    <#assign start=0>
                    <#if (formFieldVoList??) && (formFieldVoList?size>0)>
                    <#list formFieldVoList as formFieldVo>
                    <#if isRelate>
                    <#if formFieldVo.isRelated?? && formFieldVo.isRelated == '1'>
                    <#assign value = '${entity?uncap_first}Vo.${formFieldVo.field}${formFieldVo.relatedShowField}'>
                    <#else>
                    <#assign value = '${entity?uncap_first}Vo.${formFieldVo.field}'>
                    </#if>
                    <#else>
                    <#assign value = '${entity?uncap_first}.${formFieldVo.field}'>
                    </#if>
                    <#if formFieldVo.singleRow == '1'>
                    <#if start == 0>
                    <div class="layui-form-item">
                    </#if>
                        <label class="layui-form-label"><#if formFieldVo.notBlank=='1'><span class="red">*</span></#if>&nbsp;${formFieldVo.name}：</label>
                        <div class="layui-input-inline">
                            <#if formFieldVo.type == 'readOnly'>
                            <#if formFieldVo.isRelated?? && formFieldVo.isRelated == '1'>
                            <input type="text" name="${formFieldVo.field}${formFieldVo.relatedShowField}" value="${r'${'}${value}}" <#if formFieldVo.notBlank=='1'>lay-verify="required" </#if>placeholder="请输入${formFieldVo.name}" autocomplete="off" class="layui-input" readOnly>
                            <#else>
                            <input type="text" name="${formFieldVo.field}" value="${r'${'}${value}}" <#if formFieldVo.notBlank=='1'>lay-verify="required" </#if>placeholder="请输入${formFieldVo.name}" autocomplete="off" class="layui-input" readOnly>
                            </#if>
                            <#elseif formFieldVo.type == 'input'>
                            <input type="text" name="${formFieldVo.field}" value="${r'${'}${value}}" <#if formFieldVo.notBlank=='1'>lay-verify="required" </#if>placeholder="请输入${formFieldVo.name}" autocomplete="off" class="layui-input" maxlength="200">
                            <#elseif formFieldVo.type == 'select'>
                            <select name="${formFieldVo.field}" id="${formFieldVo.field}" <#if formFieldVo.notBlank=='1'>lay-verify="required" </#if>></select>
                            <#elseif formFieldVo.type == 'dateTime'>
                            <#assign d= '${'+'${value}'+'}'>
                            <#if formFieldVo.format == 'year'>
                            <#assign d1= '${'+'${value}'+'?substring(0,4)}'>
                            <#assign d2= '${'+'${value}'+'?string(\'yyyy\')}'>
                            <#elseif formFieldVo.format == 'month'>
                            <#assign d1= '${'+'${value}'+'?substring(0,7)}'>
                            <#assign d2= '${'+'${value}'+'?string(\'yyyy-MM\')}'>
                            <#elseif formFieldVo.format == 'date'>
                            <#assign d1= '${'+'${value}'+'?substring(0,10)}'>
                            <#assign d2= '${'+'${value}'+'?string(\'yyyy-MM-dd\')}'>
                            <#elseif formFieldVo.format == 'time'>
                            <#assign d1= '${'+'${value}'+'?substring(11,19)}'>
                            <#assign d2= '${'+'${value}'+'?string(\'HH:mm:ss\')}'>
                            <#elseif formFieldVo.format == 'datetime'>
                            <#assign d1= '${'+'${value}'+'?substring(0,19)}'>
                            <#assign d2= '${'+'${value}'+'?string(\'yyyy-MM-dd hh:mm:ss\')}'>
                            </#if>
                            <input type="text" name="${formFieldVo.field}" id="${formFieldVo.field}" value="${'<#if ${value}??><#if ${value}?is_date>${d2}<#elseif ${value}?is_string>${d1}</#if><#else>${d}</#if>'}" <#if formFieldVo.notBlank=='1'>lay-verify="required" </#if>placeholder="请输入${formFieldVo.name}" autocomplete="off" class="layui-input">
                            <#elseif formFieldVo.type == 'textarea'>
                            <textarea class="layui-textarea" name="${formFieldVo.field}" <#if formFieldVo.notBlank=='1'>lay-verify="required" </#if>autocomplete="off" placeholder="请输入${formFieldVo.name}" maxlength="2000">${r'${'}${value}}</textarea>
                            <#elseif formFieldVo.type == 'file'>
                            <div class="layui-upload" id="${formFieldVo.field}"></div>
                            </#if>
                        </div>
                    <#if start==0 &&( (formFieldVo_index == (formFieldVoList?size-1)) || ((formFieldVoList[formFieldVo_index+1]).singleRow == '2'))>
                    </div>
                    <#assign start=0>
                    <#else>
                    <#if start == 1>
                    </div>
                    <#assign start=0>
                    <#else>
                    <#assign start=1>
                    </#if>
                    </#if>
                    <#elseif formFieldVo.singleRow == '2'>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><#if formFieldVo.notBlank=='1'><span class="red">*</span></#if>&nbsp;${formFieldVo.name}：</label>
                        <div class="layui-input-inline w440">
                            <#if formFieldVo.type == 'readOnly'>
                            <#if formFieldVo.isRelated?? && formFieldVo.isRelated == '1'>
                            <input type="text" name="${formFieldVo.field}${formFieldVo.relatedShowField}" value="${r'${'}${value}}" <#if formFieldVo.notBlank=='1'>lay-verify="required" </#if>placeholder="请输入${formFieldVo.name}" autocomplete="off" class="layui-input" readOnly>
                            <#else>
                            <input type="text" name="${formFieldVo.field}" value="${r'${'}${value}}" <#if formFieldVo.notBlank=='1'>lay-verify="required" </#if>placeholder="请输入${formFieldVo.name}" autocomplete="off" class="layui-input" readOnly>
                            </#if>
                            <#elseif formFieldVo.type == 'input'>
                            <input type="text" name="${formFieldVo.field}" value="${r'${'}${value}}" <#if formFieldVo.notBlank=='1'>lay-verify="required" </#if>placeholder="请输入${formFieldVo.name}" autocomplete="off" class="layui-input" maxlength="200">
                            <#elseif formFieldVo.type == 'select'>
                            <select name="${formFieldVo.field}" id="${formFieldVo.field}" <#if formFieldVo.notBlank=='1'>lay-verify="required" </#if>></select>
                            <#elseif formFieldVo.type == 'dateTime'>
                            <#assign d= '${'+'${value}'+'}'>
                            <#if formFieldVo.format == 'year'>
                            <#assign d1= '${'+'${value}'+'?substring(0,4)}'>
                            <#assign d2= '${'+'${value}'+'?string(\'yyyy\')}'>
                            <#elseif formFieldVo.format == 'month'>
                            <#assign d1= '${'+'${value}'+'?substring(0,7)}'>
                            <#assign d2= '${'+'${value}'+'?string(\'yyyy-MM\')}'>
                            <#elseif formFieldVo.format == 'date'>
                            <#assign d1= '${'+'${value}'+'?substring(0,10)}'>
                            <#assign d2= '${'+'${value}'+'?string(\'yyyy-MM-dd\')}'>
                            <#elseif formFieldVo.format == 'time'>
                            <#assign d1= '${'+'${value}'+'?substring(11,19)}'>
                            <#assign d2= '${'+'${value}'+'?string(\'HH:mm:ss\')}'>
                            <#elseif formFieldVo.format == 'datetime'>
                            <#assign d1= '${'+'${value}'+'?substring(0,19)}'>
                            <#assign d2= '${'+'${value}'+'?string(\'yyyy-MM-dd hh:mm:ss\')}'>
                            </#if>
                            <input type="text" name="${formFieldVo.field}" id="${formFieldVo.field}" value="${'<#if ${value}??><#if ${value}?is_date>${d2}<#elseif ${value}?is_string>${d1}</#if><#else>${d}</#if>'}" <#if formFieldVo.notBlank=='1'>lay-verify="required" </#if>placeholder="请输入${formFieldVo.name}" autocomplete="off" class="layui-input">
                            <#elseif formFieldVo.type == 'textarea'>
                            <textarea class="layui-textarea" name="${formFieldVo.field}" <#if formFieldVo.notBlank=='1'>lay-verify="required" </#if>autocomplete="off" placeholder="请输入${formFieldVo.name}" maxlength="2000">${r'${'}${value}}</textarea>
                            <#elseif formFieldVo.type == 'file'>
                            <div class="layui-upload" id="${formFieldVo.field}"></div>
                            </#if>
                        </div>
                    </div>
                    <#assign start=0>
                    </#if>
                    </#list>
                    </#if>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block" style="margin-left: 0px !important;text-align: center">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="submitBtn">提交</button>
                <button type="button" id="cancel" class="layui-btn layui-btn-primary">取消</button>
                <button type="button" style="display: none;" id="save" class="layui-btn layui-btn-primary"></button>
            </div>
        </div>
    </form>
</div>
<script src="${basePath}/lib/layui/layui.js" type="text/javascript" charset="utf-8"></script>
<script src="${basePath}/js/common.js" type="text/javascript" charset="utf-8"></script>
<script>
    layui.use(['jquery', 'form', <#if showPage>'page', </#if><#if showLaydate>'laydate', </#if><#if showFileUtil>'fileUtil', </#if>'baseutil'], function () {
        var $ = layui.jquery,
            form = layui.form,
            <#if showPage>
            page = layui.page,
            </#if>
            <#if showLaydate>
            laydate = layui.laydate,
            </#if>
            <#if showFileUtil>
            fileUtil = layui.fileUtil,
            </#if>
            baseutil = layui.baseutil;
        <#assign initIndex=0>
        <#if (formFieldVoList??) && (formFieldVoList?size>0)>
        <#list formFieldVoList as formFieldVo>
        <#if formFieldVo.type == 'dateTime'>
        <#if initIndex == 0>

        //初始化时间控件
        </#if>
        <#assign initIndex++>
        laydate.render({elem: '#${formFieldVo.field}', type: '${formFieldVo.format}'});
        </#if>
        </#list>
        </#if>
        <#assign initIndex=0>
        <#if (formFieldVoList??) && (formFieldVoList?size>0)>
        <#list formFieldVoList as formFieldVo>
        <#if formFieldVo.type == 'file'>
        <#if initIndex == 0>

        //初始化附件控件
        </#if>
        <#assign initIndex++>
        <#if isRelate>
        <#assign value = '${entity?uncap_first}Vo.${formFieldVo.field}'>
        <#else>
        <#assign value = '${entity?uncap_first}.${formFieldVo.field}'>
        </#if>
        fileUtil.uploadMultiFile('${formFieldVo.field}', "${module}/mult", '${r'${'}${value}}');
        </#if>
        </#list>
        </#if>

        <#if showPage>
        page.initDict('${allSelect}', function (dictData) {
            <#if (fieldSelectList??) && (fieldSelectList?size>0)>
            <#list fieldSelectList as fieldSelect>
            <#if isRelate>
            <#assign value = '${entity?uncap_first}Vo.${fieldSelect.field}'>
            <#else>
            <#assign value = '${entity?uncap_first}.${fieldSelect.field}'>
            </#if>
            page.showDict($("#${fieldSelect.field}"), page.aceeptDictContentList(dictData, '${fieldSelect.code}'), "请选择", '${r'${'}${value}}');
            </#list>
            </#if>
        });
        </#if>

        //监听提交
        form.on('submit(submitBtn)', function (data) {
            <#if isRelate>
            <#assign id = '${entity?uncap_first}Vo.id'>
            <#else>
            <#assign id = '${entity?uncap_first}.id'>
            </#if>
            data.field.id = '${r'${'}${id}}';
            baseutil.post("/${module}/${entity?replace(module,'')?lower_case}/addOrUpdate", data.field, function () {
                $("#save").click();
            });
            return false;
        });
    });
</script>
</body>
</html>